package com.skyolder.milkbee.tool;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

import javax.servlet.ServletContext;

public class FileUtil {
	private static String realRootDir;
	public static void cpFile(String src, String dst) {

		File in = new File(src); // 资源文件夹
		File out = new File(dst); // 目标文件夹

		try {
			Files.copy(in.toPath(), out.toPath(), StandardCopyOption.REPLACE_EXISTING);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static boolean renameFile(String src, String dst) {
		File srcFile = new File(src); // 资源文件夹
		File dstFile = new File(dst); // 目标文件夹
		boolean b = srcFile.renameTo(dstFile);
		return b;
	}

	public static String getWebRealPath(String shortPath) {
		System.out.println("@@@@@@@@@@@@@@"+ realRootDir+shortPath);
		return realRootDir+shortPath;
	}
	public static void init(ServletContext servletContext){
		realRootDir=servletContext.getRealPath("/");
	}
}
